import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;

public class aaaa {
    public static void main(String[] args) {
        int[] nums1 = {0,1,2,2,3,0,4,2,1,2,3,4,5,5};
        System.out.println(removeElement(nums1, 2));

    }
    public static int removeElement(int[] nums, int val) {
        Map<Integer, Integer> numCountMap = new LinkedHashMap<>(nums.length);
        int size = numCountMap.size();
        int p1 = 0;
        int p2 = nums.length - 1;
        int temp;
        while(p2 >= 0 && p1 <= p2){
            if(nums[p2] == val){
                p2 --;
            }else if(nums[p1] == val){
                temp = nums[p1];
                nums[p1] = nums[p2];
                nums[p2] = temp;
                p1++;
                p2--;
            }else{
                p1++;
            }
        }
        System.out.println(Arrays.toString(nums));
        return p1;
    }
}
